#coding=utf-8
from hengpan import is_hengpan, get_hp
from turtle import is_gtendtop, get_top
from hpjump.startdb import get_jump

from stutils import *
set_django_environ()
from stdj.stock.models import *
from stsettings import datadir

dbfn = '%s/strategy.db'%datadir
def get_con():
    return get_dbconnector(dbfn)
    
tb_selected = '''
create table if not exists selected
(id integer primary key,
 strategy text not null,
 date text not null,
 code text not null,
 name text not null) 
'''
def selected2db(con, e, sname):
    c = con.cursor()
    c.execute('insert into selected (strategy, date, code, name) values(?,?,?,?)',
              (sname, e.date.isoformat(), e.share.code, e.share.name))
    c.close()
    con.commit()
    
def afternday_change(e, n=3):
    aftere = e.afternday(n)
    if not aftere:return None
    
    ae = aftere.price.end
    e = e.price.end
    
    change = float( todec( (ae-e)*100 / e, 2 ) )
    
    return change
    
    
     
